package com.gylang.passport.service.token.impl;

import cn.hutool.core.util.IdUtil;
import com.gylang.passport.domain.token.UserToken;
import com.gylang.passport.service.token.TokenService;
import org.springframework.stereotype.Service;

import static com.gylang.common.constant.CacheConstant.AUTH_TOKEN_EXPIRE;

/**
 * @author gylang
 * data 2021/1/5
 */
@Service
public class UserTokenServiceImpl extends BaseTokenServiceImpl<UserToken> implements TokenService<UserToken> {
    @Override
    public String createToken(UserToken token) {

        // 过滤数据
        String authToken = IdUtil.objectId();
        cacheManager.setnx(assemblyAuthToken(authToken), token, AUTH_TOKEN_EXPIRE);
        return authToken;
    }

    @Override
    public UserToken getToken(String authToken) {
        return cacheManager.get(authToken);
    }

    @Override
    public boolean checkLogin(String authToken) {

        return null != cacheManager.get(authToken);
    }


}
